{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 7.29 Orifice Flow Rate Calculation"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Given a differential pressure of 17 kPa is measured across taps located 1D upstream/0.5D downstream from the inlet face of a 50 mm ID orifice plate in an 80 mm schedule 80 steel pipe carrying water 15 deg C. \n",
    "Find the flow rate in gallons/minute."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "0.07366 meter"
      ],
      "text/latex": [
       "$0.07366\\ \\mathrm{meter}$"
      ],
      "text/plain": [
       "0.07366 <Unit('meter')>"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from fluids.units import *\n",
    "from thermo.units import Chemical\n",
    "\n",
    "P1 = 2*u.bar # The full set of equations requires actual pressures not just the pressure difference, so an initial pressure of 2 bar is assumed.\n",
    "P2 = P1 -  17*u.kPa\n",
    "taps = 'D'\n",
    "meter_type = 'ISO 5167 orifice'\n",
    "Do = 50*u.mm\n",
    "\n",
    "NPS, D, _, t_pipe = nearest_pipe(Do=80*u.mm, schedule=80)\n",
    "\n",
    "D"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(999.149354395164 <Unit('kilogram / meter ** 3')>,\n",
       " 0.0011375132802133906 <Unit('pascal * second')>,\n",
       " 1.329536639348325 <Unit('dimensionless')>)"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "water = Chemical('water', T=15*u.degC, P=P1)\n",
    "rho = water.rho\n",
    "mu = water.mu\n",
    "k = water.isentropic_exponent\n",
    "rho, mu, k"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "7.704278611291563 kilogram / second\n",
      "462.6502680946246 liter / minute\n"
     ]
    }
   ],
   "source": [
    "m = differential_pressure_meter_solver(D=D, D2=Do, P1=P1, P2=P2, rho=rho, mu=mu, k=k, meter_type=meter_type, taps=taps)\n",
    "print(m)\n",
    "Q = m/rho\n",
    "print(Q.to('L/min'))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The answer given in TP410M is 478 gallons/minute; however the errata\n",
    "specifies this value is in units of liters/minute instead.\n",
    "\n",
    "This calculation matches their result well, given they did not include expansivity in their calculations and read a value of C from a graph.\n",
    "\n",
    "A calculator at flow of fluids, which also does not include expansivity, gives an answer of 476.777 L/min, along with 7.93916 kg/s  (http://www.flowoffluids.com/calculators/flow-through-orifices.aspx)."
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
